package plantshop.view.listeners;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.Serializable;
import java.util.Map;

import javax.swing.JFrame;
import javax.swing.event.MouseInputListener;

import plantshop.view.MainMenu;
import plantshop.view.ScoreScreen;


public class ScoreScreenMouseListener implements MouseInputListener, Serializable {
	private static final long serialVersionUID = -391303459425235945L;
	final static Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
	final static int frameWidth = screenSize.width;
   	final static int frameHeight = screenSize.height;
   	
	private ScoreScreen scores;
	private JFrame frame;
	private Map<String, BufferedImage> images;
	private Map<String, BufferedImage[]> animations;
	
	public ScoreScreenMouseListener(ScoreScreen scores, Map<String, BufferedImage> images, JFrame frame,  Map<String, BufferedImage[]> animations){
		this.scores = scores;
		this.images = images;
		this.animations = animations;
		this.frame = frame;
	}

	
	
	@Override
	public void mouseClicked(MouseEvent e) {
	}

	@Override
	public void mousePressed(MouseEvent e) {
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		int[] coords = scores.getScoreButtonCoords();
		Point p = e.getPoint();
		int xloc = p.x;
		int yloc = p.y;
		
		int xmin, ymin, xmax, ymax;
		
		for(int i=0; i < coords.length; i+=4){
			xmin = coords[i+0];
			ymin = coords[i+1];
			xmax = coords[i+0]+coords[i+2];
			ymax = coords[i+1]+coords[i+3];
			
			System.out.println(xloc+","+yloc);
			System.out.println(xmin+","+ymin+" "+xmax+","+ymax);
			if((xloc <= xmax && xloc >= xmin) && (yloc >= ymin && yloc <= ymax)){
				if(i == 8){
					frame.getContentPane().removeAll();
					try {
						frame.getContentPane().add(new MainMenu(images, frame, animations));
						frame.validate();
						frame.repaint();
					} catch (IOException e1) {
						e1.printStackTrace();
					}
					
				}
			}
		}
	}

	@Override
	public void mouseEntered(MouseEvent e) {
	}

	@Override
	public void mouseExited(MouseEvent e) {
	}

	@Override
	public void mouseDragged(MouseEvent e) {
	}

	@Override
	public void mouseMoved(MouseEvent e) {
	}

}